﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using Jy123.Common;//

namespace Jy123.Web.home
{
    /// <summary>
    /// AjaxService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
     [System.Web.Script.Services.ScriptService]
    public class AjaxService : System.Web.Services.WebService
    {

        [WebMethod]
        public bool CheckEmailAvailability(string email)
        {
            Jy123.BLL.User.UserSql bllUserSql = new Jy123.BLL.User.UserSql();
            bool emailIsAvailable = bllUserSql.CheckEmailAvailability(email);
            if (emailIsAvailable) { return true; }
            return false;
        }

        [WebMethod]
        public bool CheckUserPsw(string email, string psw)
        {
            Jy123.BLL.User.UserSql bllUserSql = new Jy123.BLL.User.UserSql();
            bool blPsw = bllUserSql.CheckPassword(email, psw);
            if (blPsw) 
            {
                Jy123.BLL.User.UserSql usSql = new Jy123.BLL.User.UserSql();
                int userId = 0;
                string userName = string.Empty;
                string userPortrait = string.Empty;
                int loginNum = 0;
                //登陆状态
                Jy123.BLL.User.EnumLoginState state = usSql.Login(email, psw, out userId, out userName, out userPortrait, out loginNum);
                Model.User_Main modelUser = new Jy123.Model.User_Main();
                //BLL.User_Main bllUser = new Jy123.BLL.User_Main();
                modelUser.ID = userId;
                modelUser.Email = email;
                modelUser.UserName = userName;

                Jy123.Common.Cookie.SetCookie("SNSUserPassPort", modelUser.ToString(), 20);    //设置COOKIE
                Cookie.SetCookie("UserName", userName);
                Cookie.SetCookie("UserID", userId.ToString());
                Cookie.SetCookie("UserEmail", email);
                return true; 
            }
            return false;
        }
    }
}
